<?php

namespace app\admin\controller;

use app\blog\model\AdminModel;
use app\blog\model\VisitorModel;
use think\Controller;


class Index extends Controller
{
    public function index()
    {
        if (!session('name')) {
            $this->redirect('admin/index/login');
        }
        $visitorModel = new VisitorModel();
        $data = $visitorModel->NumofWeek();
        $this->assign('num0', $data['num'][0]);
        $this->assign('num1', $data['num'][1]);
        $this->assign('num2', $data['num'][2]);
        $this->assign('num3', $data['num'][3]);
        $this->assign('num4', $data['num'][4]);
        $this->assign('num5', $data['num'][5]);
        $this->assign('num6', $data['num'][6]);
        $this->assign('num7', $data['num'][7]);
        $this->assign('date0', $data['date'][0]);
        $this->assign('date1', $data['date'][1]);
        $this->assign('date2', $data['date'][2]);
        $this->assign('date3', $data['date'][3]);
        $this->assign('date4', $data['date'][4]);
        $this->assign('date5', $data['date'][5]);
        $this->assign('date6', $data['date'][6]);
        $this->assign('date7', $data['date'][7]);

        $stt = $visitorModel->stt();
        $this->assign('ip_num',$stt[0]);
        $this->assign('pv_num',$stt[1]);

        return view();
    }

    /**
     * 登录
     * @return \think\response\View
     */
    public function login()
    {
        if (request()->isPost()) {
            $username = $_POST['username'];
            $pass = md5($_POST['password']);
            $adminModel = new AdminModel();
            $conn = $adminModel->get(1);
            if ($username == $conn['username'] & $pass == $conn['password']) {
                session('name', $conn['nickname']);
                $this->redirect('admin/index/index');
            }
        } else {
            session(null);
            return view();
        }
    }
}